package com.example.partner.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.partner.R;
import com.example.partner.model.domain.User;

import java.util.List;

public class UserAdapter extends BaseAdapter {
    private Context context;
    private List<User> userList;

    public UserAdapter(Context context, List<User> userList) {
        this.context = context;
        this.userList = userList;
    }

    @Override
    public int getCount() {
        return userList.size();
    }

    @Override
    public Object getItem(int position) {
        return userList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.user_list, parent, false);
        }
        ImageView avatarUrl = convertView.findViewById(R.id.avatarUrl);
        TextView nameTextView = convertView.findViewById(R.id.username);
        TextView tagsTextView = convertView.findViewById(R.id.tags);
        TextView profileTextView = convertView.findViewById(R.id.profile);
        User user = userList.get(position);
        nameTextView.setText(user.getUsername());
        Glide.with(context).load(user.getAvatarUrl()).into(avatarUrl);
        tagsTextView.setText(user.getTags());
        profileTextView.setText(user.getProfile());


        return convertView;
    }
}
